package com.heima.controller;


import com.heima.pojo.dto.PartnerAddDto;
import com.heima.pojo.dto.PartnerSearchDto;
import com.heima.pojo.vo.PageResponseVo;
import com.heima.pojo.vo.PartnerVo;
import com.heima.service.PartnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user-service/partner")
public class PartnerController {


    @Autowired
    private PartnerService partnerService;
    //分页展示合作商数据 根据合作商名称动态查询
    @GetMapping("/search")
    public PageResponseVo<PartnerVo> searchPartner(PartnerSearchDto partnerSearchDto){
        return partnerService.searchPage(partnerSearchDto.getPageSize(), partnerSearchDto.getPageIndex(), partnerSearchDto.getName());
    }

    //新增合作商
    @PostMapping
    public boolean addPartner(@RequestBody PartnerAddDto partnerAddDto){
        return partnerService.addPartner(partnerAddDto);
    }

    //查询合作商详情
    @GetMapping("/{id}")
    public PartnerVo getPartner(@PathVariable Long id){
        return partnerService.getPartner(id);
    }

    //修改合作商
    @PutMapping("/{id}")
    public boolean updatePartner(@PathVariable Long id, @RequestBody PartnerAddDto partnerAddDto){
        return partnerService.updatePartner(id, partnerAddDto);
    }

    //根据id删除合作商
    @DeleteMapping("/{id}")
    public boolean deletePartner(@PathVariable Long id){
        return partnerService.removeById(id);
    }
}
